#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<string>
int main()
{
	int capacityA, capacityB;
	scanf("%d%d", &capacityA, &capacityB);
	int callA, guessA, callB, guessB;
	int n;
	scanf("%d", &n);
	int drinkA = 0, drinkB = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d%d%d", &callA, &guessA, &callB, &guessB);
		int sum = callA + callB;
		if ((guessA == sum && guessB == sum)||(guessA != sum && guessB != sum))
			continue;
		if (guessA == sum)
		{
			drinkA++;
			if (drinkA > capacityA)
			{
				printf("A\n%d", drinkB);
				break;
			}
		}
		if (guessB == sum)
		{
			drinkB++;
			if (drinkB > capacityB)
			{
				printf("B\n%d", drinkA);
				break;
			}
		}
	}
	system("PAUSE");
	return 0;
}